// customButton.js  
import { Boot, IButtonMenu } from '@wangeditor/editor'  
import { DownloadOutlined } from '@ant-design/icons';

// 定义自定义按钮类  
class ExportButton implements IButtonMenu {
    title = '导出';
    tag = 'button';
    iconSvg = '<svg viewBox="64 64 896 896" focusable="false" data-icon="download" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M505.7 661a8 8 0 0012.6 0l112-141.7c4.1-5.2.4-12.9-6.3-12.9h-74.1V168c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v338.4H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.8zM878 626h-60c-4.4 0-8 3.6-8 8v154H214V634c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v198c0 17.7 14.3 32 32 32h684c17.7 0 32-14.3 32-32V634c0-4.4-3.6-8-8-8z"></path></svg>';

    getValue() { return '' }
    isActive() { return false }
    isDisabled() { return false }
    exec(editor: any) {
      if(!editor) {
        return;
      }
      const config = editor.getConfig();
      const exportFunc = config.MENU_CONF?.export?.execFunc;
      if(!exportFunc) {
        return;
      }
      exportFunc();
    }
}


// 定义自定义按钮类  
class UploadButton implements IButtonMenu {
  title = '上传';
  tag = 'button';
  iconSvg = '<svg viewBox="64 64 896 896" focusable="false" data-icon="to-top" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M885 780H165c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h720c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zM400 325.7h73.9V664c0 4.4 3.6 8 8 8h60c4.4 0 8-3.6 8-8V325.7H624c6.7 0 10.4-7.7 6.3-12.9L518.3 171a8 8 0 00-12.6 0l-112 141.7c-4.1 5.3-.4 13 6.3 13z"></path></svg>';
  getValue() { return '' }
  isActive() { return false }
  isDisabled() { return false }
  exec(editor: any) {
    if(!editor) {
      return;
    }
    const config = editor.getConfig();
    const uploadFunc = config.MENU_CONF?.upload?.execFunc;
    if(!uploadFunc) {
      return;
    }
    uploadFunc();
  }
}



// 定义菜单配置  
export const exportButtonMenuConf = {  
  key: 'export',  // 菜单唯一标识
  factory() {  
    return new ExportButton()  
  }  
}

export const uploadButtonMenuConf = {  
  key: 'upload',  // 菜单唯一标识
  factory() {  
    return new UploadButton()  
  }  
}

// 注册自定义菜单  
Boot.registerModule({  
  menus: [exportButtonMenuConf, uploadButtonMenuConf]  
})  